﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Xml;

namespace WarOfDev.AutoTasks
{
    public partial class TaskConfig : IConfigurationSectionHandler
    {
        public List<TaskEntity> list;

        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            list = new List<TaskEntity>();

            XmlNodeList nodeList = section.ChildNodes;
            foreach (XmlNode node in nodeList)
            {
                var entity = new TaskEntity();
                entity.Name = node.Attributes["name"].Value;

                int nodeInterval = 0;
                int.TryParse(node.Attributes["interval"].Value, out nodeInterval);

                entity.Interval = nodeInterval;
                entity.ExecutorType = node.Attributes["executor"].Value;

                if (entity.Interval > 0 && !string.IsNullOrEmpty(entity.ExecutorType))
                    list.Add(entity);
            }

            return list;
        }
    }
}
